package com.newlink.building.userinfo.adapter

import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.newlink.building.userinfo.R
import com.newlink.building.userinfo.bean.Module_UserInfo_CheckBean


class Module_UserInfo_AreaSelectionAdapter(data: MutableList<Module_UserInfo_CheckBean>) :
    BaseQuickAdapter<Module_UserInfo_CheckBean, BaseViewHolder>(R.layout.item_area, data) {

    init {
        addChildClickViewIds(R.id.area_container)
    }

    private var mSelectItem = 0

    fun setSelectItem(position: Int) {
        // 单选
//        for (i in 0 until data.size) {
//            data[i].isChecked = false
//        }
//        data[position].isChecked = true
        // 多选
        data[position].isChecked = !data[position].isChecked
        notifyDataSetChanged()
    }

    override fun convert(holder: BaseViewHolder, item: Module_UserInfo_CheckBean) {
        val checkBox = holder.getView<ImageView>(R.id.cb_select)
        val textView = holder.getView<TextView>(R.id.tv_area)
        textView.text = item.name
//        if (data[mSelectItem].value == item.value) {
//            checkBox.setImageResource(R.drawable.checkbox_checked_ic)
//        } else {
//            checkBox.setImageResource(R.drawable.checkbox_disable_ic)
//        }
        when (item.type) {
            0 -> {
                if (item.isChecked) {
                    checkBox.setImageResource(R.drawable.checkbox_square_checked)
                } else {
                    checkBox.setImageResource(R.drawable.checkbox_square_normal)
                }
            }

            else -> {
                if (item.isChecked) {
                    checkBox.setImageResource(R.drawable.checkbox_circle_checked)
                    textView.setTextColor(context.getColor(R.color.colorPrimary))
                } else {
                    checkBox.setImageResource(R.color.white_color)
                    textView.setTextColor(context.getColor(R.color.color_3030300))
                }
            }
        }
    }
}